package cn.wizzer.app.user.modules.models;

import cn.wizzer.app.user.modules.models.enums.MsgTypeEnum;
import cn.wizzer.app.user.modules.models.enums.OprTypeEnum;
import cn.wizzer.framework.base.model.BaseModel;
import lombok.Data;
import org.nutz.dao.entity.annotation.*;
import org.nutz.dao.interceptor.annotation.PrevInsert;
import org.nutz.integration.json4excel.annotation.J4EIgnore;

/**
 * 群消息
 */
@Data
@Table("group_log")
@TableIndexes({@Index(name = "INDEX_CT_AT", fields = {"ctAt"}, unique = false)})
@TableMeta("{mysql-charset:'utf8mb4'}")
public class GroupLog extends BaseModel {

    @Column
    @Name
    @Comment("ID")
    @J4EIgnore
    @ColDefine(type = ColType.VARCHAR, width = 32)
    @PrevInsert(uu32 = true)
    private String id;

    @Column
    @ColDefine(type = ColType.VARCHAR, width = 32)
    private String groupId;

    @Column
    @Comment("创建时间")
    @PrevInsert(els = @EL("$me.now()"))
    private Long ctAt;

    @Column
    @ColDefine(type = ColType.VARCHAR, width = 32)
    private String userId;

    @Column
    @ColDefine(type = ColType.VARCHAR, width = 16)
    @Comment("消息类型")
    private MsgTypeEnum msgType;

    @Column
    @ColDefine(type = ColType.VARCHAR, width = 16)
    @Comment("操作")
    private OprTypeEnum oprType;


    @Column
    @ColDefine(type = ColType.TEXT)
    @Comment("消息内容")
    private String content;

    @Column
    @Comment("管理标志 0代表普通成员,1代表是管理员,2代表是群主")
    @ColDefine(type = ColType.INT, width = 4)
    @Default(value = "0")
    private Integer manager;

    /**
     * 创建群消息
     *
     * @param groupId
     * @param userId
     * @param oprType
     * @param msgType
     * @param content
     * @param manager
     * @return
     */
    public static GroupLog create(String groupId, String userId, OprTypeEnum oprType, MsgTypeEnum msgType, String content, Integer manager) {
        GroupLog groupLog = new GroupLog();
        groupLog.setGroupId(groupId);
        groupLog.setUserId(userId);
        groupLog.setOprType(oprType);
        groupLog.setMsgType(msgType);
        groupLog.setContent(content);
        groupLog.setManager(manager);
        return groupLog;
    }

}
